package com.github.dengmin.mysql.model;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author dengmin
 * @Created 2020/6/19 21:42
 */
@Data
public class ApiResponse<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private int code = 200;
    private String message = "SUCCESS";
    private Object data;

    public static <T> ApiResponse<T> result(int code, String message, T data){
        ApiResponse<T> apiResponse = new ApiResponse<T>();
        apiResponse.setCode(code);
        apiResponse.setMessage(message);
        apiResponse.setData(data);
        return apiResponse;
    }

    public static ApiResponse<String> ok(){
        return ok("", "SUCCESS");
    }

    public static <T> ApiResponse<T> ok(T data){
        return result(200, "SUCCESS", data);
    }

    public static <T> ApiResponse<T> ok(T data, String message){
        return result(200, message, data);
    }

    public static ApiResponse<String> error(String message){
        return result(500, message, "");
    }

    public static ApiResponse<String> error(int code, String message){
        return result(code, message, "");
    }
}
